package com.antong.cloud.auth.service;

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.HashMap;
import java.util.Map;

/**
 * 对 OAuth2AccessToken 对token进行扩展增强
 */
public class CustomTokenEnhancer implements TokenEnhancer {
    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication oAuth2Authentication) {
        /*Map<String, Object> additionalInfo = new HashMap<>();
            if(oAuth2Authentication.getPrincipal() instanceof CustomUser){
            CustomUser user = (CustomUser)oAuth2Authentication.getPrincipal();
            additionalInfo.put("user_info", user);
        }
        ((DefaultOAuth2AccessToken) oAuth2AccessToken).setAdditionalInformation(additionalInfo);*/
        return oAuth2AccessToken;
    }
}
